package com.yc.shopping.dao;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.yc.shopping.util.DBHelper;


/*
 * 管理员操作的Dao类
 * admin --> AdminDao
 * 对admin表进行增删改查操作
 */

public class AdminDao {
	
	/*
	 * 
	 * 管理员登录
	 * 
	 */
	
	
	public Map<String,Object> login(String aname, String pwd) throws SQLException{
		String sql = "select aid,aname,pwd,atype,astate from tb_admin where aname = ? and pwd = ?";
		//调用DBHelper类中的SelectOneMap
		return DBHelper.selectOneMap(sql,aname,pwd);
	}
	
	/*
	 * 
	 * 查看所有管理员信息
	 */
	public List<Map<String,Object>> findAll() throws SQLException{
		String sql = "select aid,aname,pwd,atype,astate from tb_admin";
		return DBHelper.selectListMap(sql);
	}
	
	/*
	 * 将账号修改为可用或禁用
	 * aid
	 * state 1可用	2禁用
	 */
	
	public int updateState(int aid,int state) throws SQLException {
		String sql = "update tb_admin set astate = ? where aid = ?";
		return DBHelper.update(sql, state,aid);
	}
	
//	public static void main(String[] args) throws SQLException {
//		AdminDao dao = new AdminDao();
//		Map<String,Object> map = dao.login("ycinfo", "123");
//		System.out.println(map);
//		
//		List<Map<String,Object>> list = dao.findAll();
//		for(Map<String,Object> m:list) {
//			System.out.println(m);
//		}
//	}

}
